package com.boot3.pojo;

/**
 * @author wzm
 * @create 2023-11-29 16:27
 * project_name:web2310
 * @Description
 */
//用来返回所有controller的统一结果类
public class Result {
    //定义返回数据需要哪些属性
    //响应状态码 方便前端判断接口是否执行成功
    private  Integer code;//0失败  1成功

    //定义返回的提示信息 字符串
    private String msg;

    //定义返回的数据
    private Object data ;


    //携带额外的数据

    public Result() {
    }

    public Result(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    //定义成功的不返回数据的方法
    public static Result success(){
        return new Result(1,"success",null);
    }


    //定义成功的要返回数据的方法
    public static Result success(Object o){
        return new Result(1,"success",o);
    }

    //失败的方法
    public static Result error(String msg){
        return new Result(0,msg,null);
    }
}
